package com.nuhu.dao;
import com.nuhu.pojo.User;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;

@Mapper
public interface UserDao {
    @Insert("INSERT INTO  users (phone_number, password, id_card_number, gender)" +
            "VALUES (#{phoneNumber}, #{password}, #{idCardNumber}, #{gender})")
    void insertUser(User user);
    @Select("SELECT * FROM users WHERE phone_number = #{phoneNumber}")
    User getUserByPhoneNumber(String phoneNumber);
    @Select("SELECT password FROM users WHERE phone_number = #{phoneNumber}")
    String getPasswordByPhoneNumber(String phoneNumber);

    @Select("SELECT user_name FROM users WHERE phone_number = #{phoneNumber}")
    String getUserNameByPhoneNumber(String phoneNumber);

    @Select("SELECT ID_Card_Number FROM users WHERE phone_number = #{phoneNumber}")
    String getIdCardNumberByPhoneNumber(String phoneNumber);
    @Update("UPDATE users SET Balance = Balance + #{amount} WHERE Phone_Number = #{phoneNumber}")//龚邓坤增加
    void updateBalanceByPhoneNumber(@Param("phoneNumber") String phoneNumber, @Param("amount") BigDecimal amount);

    @Update("UPDATE users SET Data_Balance = Data_Balance + #{Data_Balance} WHERE Phone_Number = #{phoneNumber}")//龚邓坤增加
    void updateData_BalanceByPhoneNumber(@Param("phoneNumber") String phoneNumber, @Param("Data_Balance") BigDecimal Data_Balance);


    @Update("UPDATE users SET Data_Balance = Data_Balance + #{Data_Balance}, Package_ID = #{Package_ID} WHERE Phone_Number = #{phoneNumber}")
    void updateDataBalanceAndPackageIdByPhoneNumber(@Param("phoneNumber") String phoneNumber, @Param("Data_Balance") BigDecimal Data_Balance, @Param("Package_ID") int Package_ID);
    @Select("select Phone_Number from users where Phone_Number=#{phoneNumber}")
    boolean existsByPhoneNumber(String phoneNumber);
    @Insert("INSERT INTO users (Phone_Number, Package_ID, ID_Card_Number, User_Name) " +
            "VALUES (#{phoneNumber}, #{newPackageId}, #{idCardNumber}, #{userName})")
    void insertPhone(@Param("newPackageId") int newPackageId,
                     @Param("phoneNumber") String phoneNumber,
                     @Param("userName") String userName,
                     @Param("idCardNumber") String idCardNumber);
}